package com.wf.day_0612.test4;



import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 记录程序开始时间
        long startTime = System.nanoTime();

        ArrayList<String> arrayList = new ArrayList<>();

        Random random = new Random();
        int i1 = random.nextInt(100);
        MyCallable myCallable = new MyCallable();
        i1=100;
        for (int i = 0; i < i1; i++) {

            FutureTask<String> stringFutureTask = new FutureTask<String>(myCallable);
            Thread thread = new Thread(stringFutureTask);
            thread.start();
            arrayList.add(stringFutureTask.get()+"-"+i);
        }
        System.out.println(arrayList.size());
        System.out.println(i1);
        System.out.println(arrayList);
        // 记录程序结束时间
        long endTime = System.nanoTime();
        // 计算程序运行时间（以毫秒为单位）
        long durationInNano = endTime - startTime;
        double durationInMilli = (double) durationInNano / 1_000_000; // 将纳秒转换为毫秒

        System.out.println("程序运行时间： " + durationInMilli + " 毫秒");
    }
}